<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/8/9
 * Time: 14:06
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\business;


use app\common\model\mysql\GoodsCarousel as ModelObj;
use app\common\validate\GoodsCarousel as ValidateObj;
use think\Exception;
use think\facade\Log;

class GoodsCarousel extends BusBase
{
    protected ?ModelObj $modelObj = null;
    protected ?ValidateObj $validateObj = null;
    //是否验证允许重复
    protected bool $repeat = false;
    //验证数据库重复字段
    protected string $repeat_string = '';

    public function __construct()
    {
        $this->modelObj = new ModelObj();
        $this->validateObj = new ValidateObj();
    }

    public function saveAll(array $data = [], int $goods_id = 0)
    {
        if (empty($data)) {
            return false;
        }
        $images = [];
        foreach ($data as $k => $v) {
            $images[$k]['image'] = $v;
            $images[$k]['goods_id'] = $goods_id;
        }
        try {
            $result = $this->addAll($images);
        } catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }
        if ($result) {
            return $result;
        } else {
            return false;
        }
    }

}